<template>
    <div class="all">
        <!-- <div style="text-align:center;font-size:28px;font-weight:bold;">{{$route.name}}</div> -->
        <div class="search">
            <!-- label-width="85px" -->
            <el-form ref="form" :model="platformSearch" :inline="true" size="mini">
                <el-form-item label="姓名：">
                    <el-input v-model="platformSearch.name" clearable placeholder="请输入姓名"></el-input>
                </el-form-item>
                <el-form-item label="联系方式：">
                    <el-input
                        v-model="platformSearch.phone"
                        maxlength="11"
                        clearable
                        placeholder="请输入联系方式"
                    ></el-input>
                </el-form-item>
                <el-form-item label="车牌：">
                    <!-- <el-input v-model="platformSearch.car_id" clearable placeholder="请输入车牌"></el-input> -->
                    <el-select v-model="platformSearch.car_id" clearable placeholder="请选择车牌">
                        <el-option v-for="item in carname" :key="item.id" :label="item.plate_number" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="searchClick(2)">查 询</el-button>
                </el-form-item>
            </el-form>
        </div>
        <!-- <div class="btn">
            <el-button size="medium" type="primary" @click="remove()">删 除</el-button>
        </div>-->
        <div class="table">
            <!-- 表格 -->
            <el-table
                :data="platformTable"
                border
                height="560"
                :style="{width:screenWidth+'px'}"
                :cell-style="cellStyle"
                :header-cell-style="rowClass"
                @selection-change="allSelectionChange"
            >
                <!-- <el-table-column type="selection" width="80px"></el-table-column> -->
                <el-table-column type="index" label="序号" width="80px"></el-table-column>
                <!-- <el-table-column label="订单号" width="200px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.orderNumber }}</span>
                    </template>
                </el-table-column>-->
                <!-- <el-table-column label="申请车辆" width="200px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.car_id }}</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="姓名" width="160px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.name }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="联系方式" width="140px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.phone }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="车牌" width="120px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.car_id | plateNumber }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="车辆类型" width="120px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.car_id | carType }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="车架号" width="220px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.car_id | chassisNumber }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="合作平台" width="120px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.platform }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="到期时间" width="110px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.end_time*1000 | formatDate }} {{ scope.row.end_time*1000 | formatDateBehind }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="证明" width="120px">
                    <template slot-scope="scope">
                        <div @click="browseProveUrl(scope.$index, scope.row)">
                            <img :src="scope.row.image_url" style="width:50px;" alt="证书图片" />
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="添加时间" width="100px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.car_id | createTime }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="状态" width="140px">
                    <template slot-scope="scope">
                        <span>{{ runstate[scope.row.state] }}</span>
                    </template>
                </el-table-column>
                <el-table-column show-overflow-tooltip label="备注" width="200px">
                    <template slot-scope="scope">
                        <span>{{ scope.row.reason }}</span>
                        <!-- <span>积分打开龙撒娇的卡萨姐夫考虑到是放假的看啦积分可带来撒酒疯昆仑大厦金啊发几点开始拉复健科的撒积分可带来四件啊罚款来打扫发就打开了撒交罚款单砂浆款放大镜昂克赛拉</span> -->
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="140px">
                    <template slot-scope="scope">
                        <!-- <el-button
                            size="small"
                            type="primary"
                            @click="edit(scope.$index, scope.row)"
                        >修改</el-button>
                        <el-button
                            size="small"
                            type="danger"
                            @click="remove(scope.$index, scope.row)"
                        >删除</el-button> -->
                        <div v-if="jurisdiction.update_state === 1">
                            <span v-if="scope.row.state !== 0">已审批</span>
                            <el-button
                                v-else
                                size="small"
                                type="warning"
                                @click="approval(scope.$index, scope.row)"
                            >审批</el-button>
                        </div>
                        <div v-else>
                            <span v-if="scope.row.state !== 0">已审批</span>
                            <span v-else>待审批</span>
                        </div>
                    </template>
                </el-table-column>
            </el-table>

            <!-- 分页 -->
            <el-pagination
                @size-change="pageCount"
                @current-change="currentPageCount"
                :current-page="currentPage"
                :page-sizes="[100, 500,1000,1500, 2000]"
                :page-size="currentCount"
                layout="prev, pager, next, jumper, sizes,total"
                :total="pageResultSize"
            ></el-pagination>
        </div>
        <div>
            <el-dialog center width="600px" top="5%" :visible.sync="dialogVisible">
                <div style="text-align:center;">
                    <img width="250px" height="auto" :src="dialogImageUrl" alt />
                </div>
            </el-dialog>
            <!-- 修改对话框 -->
            <!-- <el-dialog title="修改" width="60%" :visible.sync="editVisible" center @close="closeEdit">
                <el-form :model="editPlatform">
                    <el-form-item label="姓名：" :label-width="formLabelWidth">
                        {{editPlatform.name}}
                        
                    </el-form-item>
                    <el-form-item label="车牌：" :label-width="formLabelWidth">
                        {{editPlatform.car_id}}
                        
                    </el-form-item>
                    <el-form-item label="状态：" :label-width="formLabelWidth">
                        <el-radio v-model="editPlatform.status" label="1">正常</el-radio>
                        <el-radio v-model="editPlatform.status" label="2">已停用</el-radio>
                    </el-form-item>
                </el-form>
                <div slot="footer">
                    <el-button @click="cancelEdit">取 消</el-button>
                    <el-button type="primary" @click="confirmEdit">确 定</el-button>
                </div>
            </el-dialog> -->
            <!-- 审批对话框 -->
            <el-dialog
                title="审批"
                width="400px"
                :visible.sync="approvalVisible"
                center
                @close="closeApproval"
            >
                <el-form :model="approvalPlatform">
                    <el-form-item
                        label="姓名："
                        :label-width="formLabelWidth"
                    >{{approvalPlatform.name}}</el-form-item>
                    <el-form-item
                        label="车牌："
                        :label-width="formLabelWidth"
                    >{{approvalPlatform.car_id |  plateNumber }}</el-form-item>
                    <el-form-item
                        label="到期时间："
                        :label-width="formLabelWidth"
                    >{{approvalPlatform.end_time*1000 | formatDate }} {{approvalPlatform.end_time*1000 | formatDateBehind }}</el-form-item>
                    <el-form-item
                        label="合作平台："
                        :label-width="formLabelWidth"
                    >{{approvalPlatform.platform}}</el-form-item>
                </el-form>
                <div slot="footer">
                    <el-button @click="cancelApproval">拒 绝</el-button>
                    <el-button type="primary" @click="confirmApproval">通 过</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import "../../../static/scss/page.scss";
import utils from "../../util/request";
import {date} from "../../util/time.js"
import {formatDate} from "../../util/time.js"
var that
export default {
    data() {
        return {
            // 分页
            jurisdiction: null,
            currentPage: 1, //初始页面
            currentCount: 100, //当前页面的数据数量
            pageResultSize: 10, //表格数据总数
            screenWidth: window.innerWidth, //可视宽度
            dialogVisible: false, //放大图片的对话框显示
            dialogImageUrl: "", //放大图片的路径
            editVisible: false, //修改对话框
            approvalVisible: false, //审批对话框
            formLabelWidth: "100px", //对话框的label宽度
            carname: null,
            editPlatform: {
                // 修改对话框
                name: "", //姓名
                car_id: "", //车牌
                status: "" //状态
            },
            approvalPlatform: {
                // 审批对话框
                id: "",
                name: "", //姓名
                car_id: "", //车牌
                end_time: "", //到期时间
                platform: "" //合作平台
            },
            platformSearch: {
                //搜索
                // orderNumber: "", //订单号
                name: "",//姓名
                car_id: "", //车牌
                phone: "", //联系方式
                // storeName: "", //店铺名
                // dataTime: "" //订单日期
            },
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() > Date.now();
                }
            },
            platformTable: [
                {
                    recordId: 1, //平台车辆Id
                    car_id: "愼襡", //用户名nickName
                    name: "123", //姓名
                    phone: "17348567495", //联系方式phone
                    vin: "深圳", //车架号
                    car_id: "粤B13512", //车牌
                    carType: "小汽车", //车辆类型
                    platform: "滴滴", //合作平台
                    end_time: "2023-09-15", //到期时间
                    createTime: "2020-09-15", //添加时间orderTime
                    status: "审批中" //状态status
                },
                {
                    recordId: 2, //平台车辆Id
                    car_id: "亦是", //用户名nickName
                    name: "123", //姓名
                    phone: "17348567495", //联系方式phone
                    vin: "深圳", //车架号
                    car_id: "粤B746d5", //车牌
                    carType: "越野", //车辆类型
                    platform: "滴滴1", //合作平台
                    end_time: "2021-10-28", //到期时间
                    createTime: "2020-09-15", //添加时间orderTime
                    status: "已通过" //状态status
                },
                {
                    recordId: 3, //平台车辆Id
                    car_id: "无畏", //用户名nickName
                    name: "123", //姓名
                    phone: "17348567495", //联系方式phone
                    vin: "深圳", //车架号
                    car_id: "粤B7s635", //车牌
                    carType: "商务", //车辆类型
                    platform: "滴滴2", //合作平台
                    end_time: "2024-09-20", //到期时间
                    createTime: "2020-07-23", //添加时间orderTime
                    status: "已拒绝" //状态status
                }
            ],
            selectTable: [], //选中要删除的数组
            cartype:[
                {id:1,name:"轿车"},
                {id:2,name:"SUV"},
                {id:3,name:"MPV"},
            ],
            runstate:["等待审批","通过","拒绝"]
        };
    },
    filters: {
        
        // 车牌
        plateNumber(id){
            if(that.carname !== null){
                that.carname.forEach(item=>{
                    id === item.id ? id = item.plate_number : "";
                })
            }
            return id
        },
        // 车架号
        chassisNumber(id){
            if(that.carname !== null){
                that.carname.forEach(item=>{
                    id === item.id ? id = item.chassis_number : "";
                })
            }
            return id
        },
        // 车辆类型
        carType(id){
            if(that.carname !== null){
                that.carname.forEach(item=>{
                    id === item.id ? id = that.cartype[item.type-1].name : "";
                })
            }
            return id
        },
        // 添加时间
        createTime(id){
            if(that.carname !== null){
                that.carname.forEach(item=>{
                    id === item.id ? id = date(item.create_time*1000) : "";
                })
            }
            return id
        },
        // 时间戳转换
        formatDate(time){
			var date = new Date(time);
			return formatDate(date, 'yyyy-MM-dd');
		},
		formatDateBehind(time){
			var date = new Date(time);
			return formatDate(date, 'hh:mm:ss')
		}
    },
    methods: {
        goBack: function() {
            // 页头的返回
            this.$router.go(-1);
        },
        browseProveUrl(index, row) {
            this.dialogImageUrl = row.image_url;
            this.dialogVisible = true;
        },
        searchClick(num) {
            // 查询
            let data = {page:this.currentPage,list_rows:this.currentCount};
            for(var i in this.platformSearch) this.platformSearch[i] !== "" ? data[i] = this.platformSearch[i] : "";
            utils.request("/runApply/list","post",JSON.stringify(data)).then(resp=>{
                console.log(resp)
                this.platformTable = resp.data.data.data;
                this.pageResultSize = resp.data.data.total;
                if(num === 2){
                    resp.data.data.total 
                    ? this.$message({
                        message: "找到"+resp.data.data.total+"条运营车辆申请数据",
                        type: "success"
                    }) : this.$message("没有符合条件的数据");
                }else{return}
            }) 
        },
        // edit(index, row) {
        //     // 修改
        //     this.editVisible = true;
        //     this.editPlatform.name = row.name;
        //     this.editPlatform.car_id = row.car_id;
        // },
        // confirmEdit() {
        //     // 确认修改对话框
        //     this.editVisible = false;
        // },
        // cancelEdit() {
        //     // 取消修改对话框
        //     this.editVisible = false;
        // },
        // closeEdit() {
        //     // 关闭修改对话框
        //     this.editVisible = false;
        // },
        // remove(index, row) {
        //     // 删除
        // },
        approval(index, row) {
            // 审批
            console.log(index, row);
            this.approvalVisible = true;
            for(var i in this.approvalPlatform) this.approvalPlatform[i] = row[i];
            this.approvalPlatform.index = index;
            // this.approvalPlatform.name = row.name;
            // this.approvalPlatform.car_id = row.car_id;
            // this.approvalPlatform.end_time = row.end_time;
            // this.approvalPlatform.platform = row.platform;
        },
        confirmApproval() {
            // 通过审批对话框
            // console.log(this.approvalPlatform)
            
            this.$prompt("请再次确认", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                inputPlaceholder: "请输入确认通过"
            })
                .then(({ value }) => {
                    console.log(value);
                    if (value == "确认通过") {
                        utils.request("/runApply/update","post",JSON.stringify({id:this.approvalPlatform.id,state:1})).then(resp=>{
                            console.log(resp)
                            if(resp.data.code === 200){
                                let key = this.approvalPlatform.index;
                                this.platformTable[key].state = 1;
                            }
                        })
                        this.approvalVisible = false;
                    } else {
                        this.$message({
                            showClose: true,
                            type: "error",
                            message: "输入错误，请重新输入",
                            duration: 2000
                        });
                    }
                })
                .catch(() => {
                    this.$message({
                        showClose: true,
                        type: "info",
                        message: "取消拒绝",
                        duration: 2000
                    });
                });
        },
        cancelApproval() {
            // 拒绝审批对话框
            this.$prompt("请输入拒绝原因", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                inputPlaceholder: "请输入拒绝原因"
            })
                .then(({ value }) => {
                    console.log(value);
                    utils.request("/runApply/update","post",JSON.stringify({id:this.approvalPlatform.id,state:2,reason:value})).then(resp=>{
                        console.log(resp)
                        if(resp.data.code === 200){
                            let key = this.approvalPlatform.index;
                            this.platformTable[key].state = 2;
                            this.platformTable[key].reason = value;
                        }
                    })
                    this.approvalVisible = false;
                })
                .catch(() => {
                    this.$message({
                        showClose: true,
                        type: "info",
                        message: "取消拒绝",
                        duration: 2000
                    });
                });
        },
        closeApproval() {
            // 关闭审批对话框
            this.approvalVisible = false;
        },
        //   表格居中
        cellStyle: function({ row, column, rowIndex, columnIndex }) {
            return "text-align:center;";
        },
        rowClass: function({ row, rowIndex }) {
            return "text-align:center;";
        },
        allSelectionChange: function(val) {
            // 获取选中的内容
            console.log(val);
            this.selectTable = val;
        },
        // 每页数据的数量
        pageCount: function(val) {
            this.currentCount = val;
            this.searchClick(1)
        },
        // 点击的第几页
        currentPageCount: function(val) {
            this.currentPage = val;
            this.searchClick(1)
        }
    },
    created() {
        let Base64 = require("js-base64").Base64;
        let menuarr = JSON.parse(Base64.decode(sessionStorage.getItem("menuarr")))
        for(var i=0;i<menuarr.length;i++){
            // console.log(menuarr[i].link)
            if(menuarr[i].link === this.$route.path){
                this.jurisdiction = menuarr[i]
            }else{}
        }
        utils.request("/car/list","post",JSON.stringify({page:1,list_rows:999999999})).then(resp=>{
            console.log(resp)
            this.carname = resp.data.data.data;
            this.searchClick(1)
        })
    },
    computed: {},
    watch: {},
    beforeCreate() {
        that = this;
    }
};
</script>

